# -*- coding: utf-8 -*-
"""
Created on Thu Sep  8 08:45:45 2022

@author: ZXD
"""

import cv2

def CountBlackPixels(binImg):
    height = binImg.shape[0]
    width = binImg.shape[1]

    blackNums = 0
    for i in range(height):
        for j in range(width):
            if binImg[i][j] == 0:
                blackNums = blackNums+1
            
    return blackNums

def OneOrZero(img):
    grayImg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    binImg = grayImg.copy()
    height = grayImg.shape[0]
    width = grayImg.shape[1]

    for i in range(height):
        for j in range(width):
            if grayImg[i][j] >100:
                binImg[i][j] = 255
            else:
                binImg[i][j] = 0
                    
    print(CountBlackPixels(binImg))
    if CountBlackPixels(binImg) > 600:
        value = 0
    else:
        value = 1
    return value

  


img = cv2.imread('../jpg/NumH.jpg')


print(OneOrZero(img))







